package leetcode100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class lc053 {
    public static void main(String[] args) {
        String s  = "applepen";
        ArrayList<String> wordDict = new ArrayList<>();
        wordDict.add("apple");
        wordDict.add("pen");

        new lc053().wordBreak(s,wordDict);
    }

    public boolean wordBreak(String s, List<String> wordDict) {
        HashSet<String> set = new HashSet<>(wordDict);
        boolean[] dp  = new boolean[s.length()+1];
        dp[0] = true;
        for (int i = 1; i <= s.length(); i++) {

            for (int j = 0; j < i; j++) {
                if (dp[j] && set.contains(s.substring(j,i))) {
                    dp[i]=true;
                    break;
                }
            }
            System.out.println("Arrays.toString(dp) = " + Arrays.toString(dp));
        }
        return dp[s.length()];
    }
}
